'use strict';

const BaseController = require('../../core/base_controller');

class PositionController extends BaseController {
    // 获取岗位列表
    async index() {
        const { ctx } = this;
        const list = await ctx.service.cache.get('position_list','arr')
        for(let item of list){
            if(item.children){
                for(let child of item.children){
                    child.count = await ctx.model.JobOpening.count({
                        where: {
                            position_id: child.id,
                            user_type:'employer',
                            status:1,
                            del_flag:0
                        }
                    });
                }
            }
        }
        this.success(list);
    }
    async search() {
        const { ctx } = this;
        const all_position_list =  await ctx.service.cache.get('all_position_list','arr') || []
        console.log(all_position_list)
        const {keyword} = ctx.query
        const result = all_position_list.filter(item => item.parent_id && item.name.toLowerCase().includes(keyword.toLowerCase()))
        this.success(result);
    }
}

module.exports = PositionController;
